<?php
require_once("conf/_funciones.php");
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Usuario
 *
 * @author Sergio
 */
class Usuario {
    //put your code here
    public $nick= "";
    private $pass ="";
    public $fono;
    protected $priv;
    public $mail;
    function Insertar($nick, $pass, $fono, $mail) {
        global $db;
        $this->fono =$fono;
        $this->nick=$nick;
        $this->pass=$pass;
        $this->mail=$mail;
        $db->Query("INSERT INTO usuario (NICK, PASS, TELEFONO, MAIL) VALUES ('$this->nick', '".sha1($this->pass)."', '$this->fono', '$this->mail')");
    }
    function login($user, $pass) {
        global $db;
        $db->Query("SELECT * FROM ".$prefix."USUARIO WHERE NICK = ".$db->SQLValue($user, "text"));
        if ($row = $db->Row()) {
            if($row->PASS == sha1($pass)) {
                $this->nick=$nick;
                $this->pass=$pass;
                $this->fono=$row->TELEFONO;
                $this->priv=$row->PODER;
                $this->mail=$row->MAIL;
                $error = 0;
            }
            else 
                $error = 4; // Contraseña Incorrecta
        }
        else 
            $error = 6; // Usaurio No Existe
        return $error;
    }
    function getPrivilegio() {
        return $this->priv;
    }
    function exist($nick) {
        global $db;
        $db->Query("SELECT COUNT(NICK) AS COUNT FROM usuario WHERE NICK = '$nick'");
        $existe = false;
        if ($row = $db->Row()) {
            if($row->COUNT != 0)
                $existe= true;
        }
        return $existe;
    }
    function listar() {
        global $db;
        $db->Query("SELECT * FROM usuario");
        $i=0;
        $arr = array();
        while ($row = $db->Row()) {
            $arr[$i][0] = $row->UID;
            $arr[$i][1] = $row->NICK;
            $arr[$i][2] = $row->MAIL;
            $arr[$i][3] = $row->TELEFONO;
            $i++;
        }
        return $arr;
    }
}
?>